export default {
    name: 'BForms',
    methods: {
        async validate(cb, isShowNotice = true) {
            let vNodes = this.recursion(this.$slots.default, [])
            let isPass = true
            vNodes.map(async v => v.validate(valid => {if (isPass) isPass = valid}, false))
            if ((!isPass) && isShowNotice) {
                this.$noticeWarning('请填写完整')
            }
            cb(isPass)
        },
        async resetFields() {
            let vNodes = this.recursion(this.$slots.default, [])
            vNodes.map(async v => v.resetFields())
        },
        async clearValidate() {
            let vNodes = this.recursion(this.$slots.default, [])
            vNodes.map(async v => v.clearValidate())
        },
        recursion(list, vNodes) {
            // console.log(list)
            list.map(v => {
                if (v.componentInstance?.$slots.default) {
                    return this.recursion(v.componentInstance.$slots.default, vNodes)
                }
                if (v.componentOptions?.tag === 'BForm') {
                    vNodes.push(v.componentInstance)
                }
            })
            return vNodes
        }
    },
    render(h, context) {
        return <div>{this.$slots.default}</div>
    }
}
